<template>
  <div class="specsDialog">
    <el-table :data="getSpes" border style="width: 100%">
      <el-table-column prop="id" label="规格编号" width="180">
      </el-table-column>
      <el-table-column prop="specsname" label="规格名称" width="180">
      </el-table-column>
      <el-table-column prop="attr" label="规格属性">
        <template slot-scope="item">
          <div>
            <p v-for="ites in item.row.attrs" :key="ites.id">{{ ites }}</p>
          </div>
        </template> 
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="item">
          <div>
            {{ item.row.status ? "启用" : "禁止" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="地址">
        <template slot-scope="item">
          <div>
            <el-button @click="edit(item.row.id)" type="primary" size="small"
              >编辑</el-button
            >
            <el-button @click="delSpecs(item.row.id)" type="danger" size="small"
              >删除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- page-size  每页显示条目个数，支持 .sync 修饰符
    total	总条目数
    pager-count  页码按钮的数量，当总页数超过该值时会折叠
    current-change   currentPage 改变时会触发 -->
    <el-pagination
      background
      :total="getCount"
      layout="prev, pager, next"
      :page-size="getpageSize"
      @current-change="changePage"
    >
    </el-pagination>
  </div>
</template>
  <script>
import { mapActions, mapGetters } from "vuex";
import { specsdelete } from "../../request/api";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      getSpes: "specs/getSpes",
      getCount: "specs/getCount",
      getpageSize: "specs/getpageSize",
    }),
  },
  mounted() {
    this.getSpecsAction();
    this.getCountAction();
  },
  methods: {
    ...mapActions({
      getSpecsAction: "specs/getSpecsAction",
      getCountAction: "specs/getCountAction",
      getChangePage: "specs/getChangePage",
    }),
    //点击编辑按钮 显示dialog弹框
    edit(id) {
      this.$emit("edit", id);
    },
    //删除数据
    delSpecs(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          specsdelete({ id }).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.msg);
              //重新获取数据
              this.getSpecsAction();
              //重新调用总数接口
              this.getCountAction()
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //点击页码切换数据
    changePage(e) {
      this.getChangePage(e);
    },
  },
};
</script>
  <style scoped>
</style>